import { computed, defineComponent, h, ref } from 'vue'
import {
	MessageReactive,
	MessageRenderMessage,
	NAlert,
	NIcon,
	createDiscreteApi,
	darkTheme,
	lightTheme,
} from 'naive-ui'
import { RenderMessageProps } from 'naive-ui/es/message/src/types'
import { MessageOptions, MessageType } from 'naive-ui/lib'

const themeRef = ref('dark')
const configProviderPropsRef = computed(() => ({
	theme: themeRef.value === 'light' ? lightTheme : darkTheme,
}))

const {
	message,
	notification,
	dialog,
	loadingBar,
} = createDiscreteApi(['message', 'dialog', 'notification', 'loadingBar'], {
	configProviderProps: configProviderPropsRef,
	notificationProviderProps: {
		placement: 'top',
	},
})




const {
	create,
	destroyAll,
	error,
	info,
	loading,
	success,
	warning,
} = message



//  BUG:好像把这个东西放到创建里面 会导致获取不到vue实例这样就会一直报错，报错报错报错，导致onMounted,onUnmount一直出问题 ，切记切记切记切记




export const useDiscMessage = function () {
	return {
		message: {
			error(content: string, options?: MessageOptions | undefined) {

				notification.error({
					title: '错误',
					content,
					duration: options?.duration ? options.duration : 1000,
					...options,
					keepAliveOnHover: true,
				})
			},
			info(content: string, options?: MessageOptions | undefined) {


				notification.info({
					title: '信息',
					content,
					duration: options?.duration ? options.duration : 1000,
					...options,
					keepAliveOnHover: true,
				})
			},
			success(content: string, options?: MessageOptions | undefined) {


				notification.success({
					title: '成功',
					content,
					duration: options?.duration ? options.duration : 1000,
					...options,
					keepAliveOnHover: true,
				})
			},
			loading(content: string, options?: MessageOptions | undefined) {

				notification.info({
					title: '信息',
					content,
					duration: options?.duration ? options.duration : 1000,
					...options,
					keepAliveOnHover: true,
				})


			},
			warning(content: string, options?: MessageOptions | undefined) {

				notification.warning({
					title: '警告',
					content,
					duration: options?.duration ? options.duration : 1000,
					...options,
					keepAliveOnHover: true,
				})

			},

		},
		notification,
		dialog,
		loadingBar,
	}
}